<template>
  <div class="card-common-inner wise-man-integral">
    <first-level-title title="积分" />
    <van-loading v-if="isLoading" type="spinner" color="#1989fa" />
    <div v-else class="integral-info">
      <div class="integral-total">
        <div class="total">
          <div class="value" @click="handleOpenList">{{ info.SCO || 0 }}</div>
          <div class="title">今日积分</div>
        </div>
        <div class="item-total-detail">
          <div class="item-detail">
            <span>本月积分</span>
            <span>{{ info.SCO_M || 0 }}</span>
          </div>
          <div class="item-detail">
            <span>上月积分</span>
            <span>{{ info.SCO_LAST || 0 }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import firstLevelTitle from '@/components/common/firstLevelTitle.vue'
import { accountDate } from '@/api/common.js'

import { salaryTotal } from '@/api/publicline/wise.js'

import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'

export default {
  components: { firstLevelTitle },
  data() {
    return {
      isLoading: true,
      loginId: '',
      loginName: '',
      dayId: '',
      monthId: '',
      info: {}
    }
  },
  async mounted() {
    this.loginId = Vue.ls.get(USER_INFO).username
    this.loginName = Vue.ls.get(USER_INFO).realname
    await this.getAccountDate()
    await this.getAccountMonthDate()
    await this.getData()
  },
  methods: {
    // 获取日账期
    async getAccountDate() {
      const res = await accountDate({ PARAMCODE: 'D' })
      const { result, success } = res
      if (success) {
        this.dayId = result[0].value
      }
    },
    // 获取月账期
    async getAccountMonthDate() {
      const res = await accountDate({ PARAMCODE: 'M' })
      const { result, success } = res
      if (success) {
        this.monthId = result[0].value
      }
    },
    async getData() {
      this.isLoading = true
      const res = await salaryTotal({ dayId: this.dayId, monthId: this.monthId, loginId: this.loginId })
      const { result, success } = res
      if(success) {
        this.info = result[0] || {}
        this.isLoading = false
      }
    },
    handleOpenList() {
      this.$open.call(this, '/publicline/wise/integralList',
        {
          loginId: this.loginId,
          loginName: this.loginName,
          type: 'day',
          time: this.dayId
        }
      )
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@/assets/less/card.less';
.wise-man-integral {
  .integral-info {
    .integral-total {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      padding-top: 12px;
      padding-bottom: 12px;
      .total {
        text-align: center;
        width: 100px;
      }
      .value {
        font-size: 28px;
        color: #4D98FF;
        text-decoration: underline;
        margin-bottom: 4px;
      }
      .title {
        font-size: 12px;
      }
      .item-total-detail {
        flex: 1;
        margin-left: 20px;
        border-left: 1px solid #F5F5F5;
        .item-detail {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-bottom: 10px;
          margin-left: 20px;
          &:last-child {
            margin-bottom: 0;
          }
          span {
            &:first-child {
              font-size: 12px;
              color: #666;
            }
          }
        }
      }
    }
  }
}
</style>
